package com.ht.api.db.hlink.function.impl;

import javax.sql.DataSource;

import com.ht.api.db.Db;
import com.ht.api.db.Entity;
import com.ht.api.db.hlink.function.HlinkFunction;

import lombok.extern.slf4j.Slf4j;

/**
 * 获取获客链接表的main_id
 * @author asq
 * @createTime 2025年3月5日 21:46:52
 */
@Slf4j
public class GetMainIdByLinkIdFunction implements HlinkFunction<String>{
	@Override
	public String format(DataSource ds, Object value, Entity entity) {
		String linkId = entity.getStr("link_id");
		
		Entity wxCustomerLink = Db.createSqlParser("wx_customer_link").where("link_id", linkId).findOne(ds);
		
		if (wxCustomerLink == null) {
			log.error("[GetMainIdByLinkIdFunction]Hlink函数出错，根据linkId没有找到获客链接，link_id:{}", linkId);
		}
		
		return wxCustomerLink.getMainId();
	}
}
